import {reqCategoryList, reqGetBannerList, reqFloorList} from "../network/home";

const state = {
  //三级联动的数据
  categoryList: [],
  //轮播图banner
  bannerList: [],
  //floor数据
  floorList: []
};

const mutations = {
  CATEGORYLIST(state, categoryList) {
    categoryList.pop()
    state.categoryList = categoryList
  },
  GETBANNERLIST(state, bannerList) {
    state.bannerList = bannerList
  },
  GETFLOORLIST(state, floorList) {
    state.floorList = floorList
  }
};


const actions = {
  async categoryList(context) {
    let result = await reqCategoryList();
    // console.log(result)
    if (result.code === 200) {
      context.commit('CATEGORYLIST', result.data)
    }
  },

  // 获取首页轮播图数据
  async getBannerList(context) {
    let result = await reqGetBannerList()
    if (result.code === 200) {
      context.commit('GETBANNERLIST', result.data)
    }
  },

  //获取floor数据
  async getFloorList(conetxt) {
    let result = await reqFloorList()
    if (result.code === 200) {
      conetxt.commit('GETFLOORLIST', result.data)
    }
  }

};
const getters = {};

export default {
  state,
  actions,
  mutations,
  getters
}